package com.ctgu.tengyun.service.saleorder.impl;

import com.ctgu.tengyun.dao.mybatis.SaleOrderConfirmMapper;
import com.ctgu.tengyun.domain.SaleOrderConfirm;
import com.ctgu.tengyun.domain.SaleOrderConfirmExample;
import com.ctgu.tengyun.service.saleorder.SaleOrderConfirmService;
import com.ctgu.tengyun.util.CollectionsUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/7.
 */
@Service
public class SaleOrderConfirmServiceImpl implements SaleOrderConfirmService {

    @Resource
    private SaleOrderConfirmMapper mapper;

    @Override
    public int insertSelective(SaleOrderConfirm record) {
        return mapper.insertSelective(record);
    }

    @Override
    public SaleOrderConfirm selectBySaleRecordId(Long saleRecordId) {
        SaleOrderConfirmExample example = new SaleOrderConfirmExample();
        SaleOrderConfirmExample.Criteria criteria = example.createCriteria();

        criteria.andSaleRecordIdEqualTo(saleRecordId);

        List<SaleOrderConfirm> saleOrderConfirmList =  mapper.selectByExample(example);
        if(CollectionsUtil.isNotEmpty(saleOrderConfirmList)){
            return saleOrderConfirmList.get(0);
        }

        return null;
    }

    @Override
    public List<SaleOrderConfirm> selectBySaleRecordIds(Collection<Long> saleRecordIds) {
        if(!CollectionsUtil.isNotEmpty(saleRecordIds)){
            return Collections.emptyList();
        }

        SaleOrderConfirmExample example = new SaleOrderConfirmExample();
        SaleOrderConfirmExample.Criteria criteria = example.createCriteria();

        criteria.andSaleRecordIdIn(new ArrayList<>(saleRecordIds));

        return  mapper.selectByExample(example);
    }

    @Override
    public SaleOrderConfirm selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SaleOrderConfirm record) {
        return mapper.updateByPrimaryKeySelective(record);
    }
}
